import numpy as np
import random
from onnx import helper, TensorProto

def generate_gelu_model(input_names, output_names):
    """Generate Gelu operator model."""
    initializers = []
    
    shape = [1, random.randint(1,4), random.randint(10,50), random.randint(10,50)]
    approximate = random.choice(["none", "tanh"])

    data = np.random.randn(*shape).astype(np.float32)

    init_tensor = helper.make_tensor(input_names[0], TensorProto.FLOAT, shape, data.flatten().tolist())
    initializers.append(init_tensor)

    input_info = helper.make_tensor_value_info("useless_input", TensorProto.FLOAT, shape)
    output_info = helper.make_tensor_value_info(output_names[0], TensorProto.FLOAT, shape)

    node = helper.make_node(
        "Gelu", 
        inputs=[input_names[0]], 
        outputs=[output_names[0]], 
        approximate=approximate, 
        name=f"Gelu_node_approx{approximate}",
        )

    metadata = {"input_shapes": [shape], "output_shapes": [shape], "approximate": approximate}
    return [input_info], output_info, [node], initializers, metadata